package com.gem.config;

import com.gem.filter.WebInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 刘聪
 * Created  on 2020/12/15
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
//        registry.addViewController("/").setViewName("register");
//        registry.addViewController("/tologin").setViewName("login");

        registry.addViewController("/").setViewName("home");
        registry.addViewController("/login").setViewName("login");
        registry.addViewController("/register").setViewName("register");

    }

    /**
     * 配置静态资源的路径
     *
     *
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        /*file: 后面是图片在服务器上的路径*/
//        registry.addResourceHandler("/images/**").addResourceLocations("file:/Users/liu/Documents/image/");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new WebInterceptor())
                .addPathPatterns("/order/**","/cart/**","/admin/**","/user/**")
                .excludePathPatterns("/AmazeUI-2.4/**","/Admin/**","/basic/**","/css/**","/images/**","/js/**");
    }
}
